<?php
/**
 * Models Base Class
 * User: zng
 * Date: 2019/9/11
 * Time: 09:11
 */
namespace app\admin\model\admin;

use app\admin\model\Models;
use app\admin\traits\model\Permission as PermissionTraits;

class Permission extends Models
{
    use PermissionTraits;

    /**
     * 定义时间戳字段名
     * @var string
     */
    protected $updateTime = false;

    /**
     * 设置时间戳格式
     * @var string
     */
    protected $autoWriteTimestamp = true;

    /**
     * 追加字段
     * @var []
     */
//    protected $append = ['permission_category'];

    /**
     * 设置状态获取器
     * @return string
     */
    protected function getStatusTextAttr( $value, $data )
    {
        $status = config('field.permission.status');
        return $status[$data['status']]??'暂无';
    }

    /**
     * 查询状态
     * @return void
     */
    public function scopeStatus( $query, int $status = 1 )
    {
        $query->where('status', $status);
    }

    // 定义全局的查询范围
    protected function base($query)
    {
        $query->where('type',1);
    }

}